package com.quickthumb.game;

import java.util.ArrayList;

import javax.microedition.khronos.opengles.GL10;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.Log;

public class MenuTool implements UpdateAndDraw {

	public static float BLOCK_RATIO = 0.05f;
	public static float XMARGIN;
	public static float Block_width_RATIO = 0.14f;
	public static final int LIST_SIZE = 5;
	public static boolean chooseEnabled;
	public static Block list[] = new Block[LIST_SIZE];

	@Override
	public void init() {
		XMARGIN = Screen.SCREEN_WIDTH * BLOCK_RATIO;

		chooseEnabled = false;
	}

	public static Block getBlock(float x) {

		int xx = (int) Math.floor(x / (Block.Block_width + XMARGIN));
		if (xx < LIST_SIZE) {
			Log.d("block", "get block index " + xx + " " + x + " "
					+ Block.Block_width + " " + XMARGIN);
			Block b = list[xx];
			b.isActive = true;
			list[xx] = new BlockEmpty();

			return b;
		}
		else
			return new BlockEmpty();
	}

	public static void returnBlock(Block b) {
		b.isActive = false;
		Log.d("block", "blockRetruned " + b.position);
		list[b.getPosition()] = b;
	}

	@Override
	public void update() {

	}

	@Override
	public void draw(Canvas c, Paint p) {
		c.save();
		p.setARGB((int) (Player.drawer_y * 128), 0, 0, 0);
		c.drawRect(0, 0, Screen.SCREEN_WIDTH, Player.drawer_y
				* Player.DRAWER_HEIGHT * Screen.HOLE_SIZE
				+ Screen.SCREEN_YOFFSET + Screen.BOARD_YOFFSET * 2, p);
		for (int i = 0; i < LIST_SIZE; i++) {
			c.translate(XMARGIN, 0);
			// p.setARGB(0, 255, 255, 255);
			if (list[i] != null)
				list[i].draw(c, p);
			else
				Log.d("block", "null in list");
			c.translate(Block.Block_width, 0);
			// Log.d("block", Block_width+"");
		}
		c.restore();
	}

	@Override
	public void draw(GL10 gl) {

	}

	@Override
	public void destroy() {

	}

}
